/*
 * (C) Copyright 2006-2010 Nuxeo SAS (http://nuxeo.com/) and contributors.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser General Public License
 * (LGPL) version 2.1 which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl.html
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * Contributors:
 *     bstefanescu
 */
package org.nuxeo.gwt.habyt.invocation.client;

import java.io.Serializable;

/**
 * A notification that an action were done on a server object. A notification is
 * usually sent by the server in the response on an InvocationRequest but can be
 * used by a comet service to notify the client about changes done by other
 * clients.
 * 
 * Also a client component may fire a Notification to other components in the
 * client.
 * 
 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
 * 
 */
@SuppressWarnings("serial")
public class Notification implements Serializable {

    protected ObjectRef target;

    protected String action;

    protected Serializable content;

    protected Notification() {
    }

    public Notification(Referenceable target, String action) {
        this(target, action, null);
    }

    public Notification(Referenceable target, String action,
            Serializable content) {
        this.target = target.getRef();
        this.action = action;
        this.content = content;
    }

    public ObjectRef getTarget() {
        return target;
    }

    public String getAction() {
        return action;
    }

    public Serializable getContent() {
        return content;
    }

    public void setTarget(Referenceable target) {
        this.target = target.getRef();
    }

    public void setAction(String action) {
        this.action = action;
    }

    public void setContent(Serializable content) {
        this.content = content;
    }

    public boolean sameAs(Notification notification) {
        return target.sameAs(notification.getTarget())
                && action.equals(notification.getAction());
    }

    @Override
    public String toString() {
        return action + ':' + target.toString();
    }

}
